const multicastFreqSegment = {
  state: {
    multicastFreqSegment: [],
    usingMulticastFreqSegment: []
  },
  mutations: {
    setMulticastFreqSegment (state, data) {
      state.multicastFreqSegment = data
    },
    setUsingMulticastFreqSegment (state, data) {
      state.usingMulticastFreqSegment = data
    },
    pushUsingMulticastFreqSegment (state, data) {
      state.usingMulticastFreqSegment.push(data)
    },
    deleteUsingMulticastFreqSegment (state, data) {
      for (let i in state.usingMulticastFreqSegment) {
        if (state.usingMulticastFreqSegment[i].id === data.id) {
          state.usingMulticastFreqSegment.splice(i, 1)
        }
      }
    }
  },
  actions: {
    async getMulticastFreqSegment (context) {
      let response = await context.dispatch('axios', {
        method: 'get',
        url: '/api/abs/devices/multicast_freq_segment/'
      })
      context.commit('setMulticastFreqSegment', response.data)
    },
    async getUsingMulticastFreqSegment (context) {
      let response = await context.dispatch('axios', {
        method: 'get',
        url: '/api/abs/devices/multicast_freq_segment/'
      })
      context.commit('setUsingMulticastFreqSegment', response.data)
    }
  },
  getters: {
    getMulticastFreqSegmentChartData: (state) => {
      let res = []
      state.usingMulticastFreqSegment.forEach(item => {
        res.push({
          type: 'traffic',
          businessCuDevice: [item.caller_cu, item.called_cu],
          workFreq: item.caller_power,
          bandWidth: (item.caller_up_freq_end - item.caller_up_freq_begin) / 1000,
          centerFreq: (item.caller_up_freq_begin + item.caller_up_freq_end) / 2000,
          user: 'com-wave',
          fillStyle: 'rgba(107,175,229,0.4)',
          strokeStyle: 'rgba(107,175,229,1)'
        })
        res.push({
          type: 'traffic',
          businessCuDevice: [item.called_cu, item.called_cu],
          workFreq: item.called_power,
          bandWidth: (item.called_up_freq_end - item.called_up_freq_begin) / 1000,
          centerFreq: (item.called_up_freq_begin + item.called_up_freq_end) / 2000,
          user: 'com-wave',
          fillStyle: 'rgba(107,175,229,0.4)',
          strokeStyle: 'rgba(107,175,229,1)'
        })
      })
      return res
    }
  }
}
export default multicastFreqSegment
